package com.cxg.allsys.memsys.controller;


import com.cxg.allsys.memsys.pojo.Member;
import com.cxg.allsys.memsys.service.IMemberService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/api")
@Slf4j
@RestController
@Data
@CrossOrigin  //后端解决跨域
public class MemberController {

    @Autowired
    private IMemberService memberService;
    //    会员注册接口
    @RequestMapping("/Common/RegisterTMember")
    public boolean registerTMember(Member member){
        log.info("Membercontroller控制器运行registerTMember方法");
        boolean flag= memberService.save(member);
        if (flag) {
            return true;
        } else {
            return false;
        }
    }


    //    会员登录
    @RequestMapping("/Common/CheckLoginMember")
    public Member  CheckLoginMember(String UserName,String Password){
        log.info("Membercontroller会员登录=控制器运行CheckLoginMember方法");
        log.info("-----------usname--:"+UserName+"--------password:--"+Password);
        return memberService.qure(UserName,Password);

    }

    //根据id获取会员信息
    @RequestMapping("/TMember/GetCurrentTMemberById")
    public List<Member> GetCurrentTMemberById(Integer id){
        log.info("Membercontroller会员登录=控制器运行CheckLoginMember方法");
        return memberService.getById(id);
    }

    //会员中心中修改会员信息:
    @RequestMapping("/TMember/UpdateMemberForEditInfo")
    public boolean UpdateMemberForEditInfo(Member member){
        log.info("UpdateMemberForEditInfo===会员中心中修改会员信息");
        log.info(member.toString());
        boolean flag=memberService.updateMember(member);
        if (flag) {
            return true;
        } else {
            return false;
        }

    }



    //会员中心中重置秘码
    @RequestMapping("/TMember/ResetMemberPassword")
    public String ResetMemberPassword(Integer id,String OldPassWord,String NewPassWord){
        log.info('旧'+OldPassWord+'新'+NewPassWord);
        return memberService.ResetMemberPassword(id,OldPassWord,NewPassWord);
    }


    //会员注销
    @RequestMapping("/TMember/del")
    public  boolean del(Integer id){
        log.info("删除");
        log.info(String.valueOf(id));
        return memberService.del(id);
    }












}
